from joblib import load
import numpy as np

class ClassIfication(object):
    def __init__(self):
        self.knn = load('knn_classifien.joblib')
        self.scaler = load('feature_scaler.joblib')
        self.le = load('label_encoder.joblib')
        
        
    def get_predicter_category(self, new_data):
        
        feature_order = [
            'eps', 'total_revenue_ps', 'undist_profit_ps', 'gross_margin', 'fcff', 'fcfe', 'tangible_asset', 'bps', 'grossprofit_margin', 'npta'
        ]       
        
        new_values = np.array([[new_data[col] for  col in feature_order]]) 
        
        new_scaled = self.scaler.transform(new_values)
        
        predicted_label = self.knn.predict(new_scaled)
        predicted_category = self.le.inverse_transform(predicted_label)
        
        return predicted_category[0]
    
if __name__ == '__main__':
    ci = ClassIfication()
    new_data = {
        'eps':'',
        'total_revenue_ps':'',
        'undist_profit_ps':'',
        'gross_margin':'',
        'fcff':'',
        'fcfe':'',
        'tangible_asset':'',
        'bps':'',
        'grossprofit_margin':'',
        'npta':''
    }
    predicted_category = ci.get_predicter_category(new_data)
    print(predicted_category)